﻿#define _CRT_SECURE_NO_WARNINGS 1

// 1.奇数位丢弃
// 方法一：模拟
#include <iostream>
#include <vector>
using namespace std;

vector<int> v;
int n;
int main() {
    while (cin >> n)
    {
        // 每次都要清空数组
        v.clear();

        // 置数
        for (int i = 0; i <= n; ++i)
            v.push_back(i);

        while (v.size() > 1)
        {
            auto it = v.begin();
            while (it < v.end())
            {
                it = v.erase(it);
                if (it != v.end())
                    it++;
            }
        }
        cout << v[0] << endl;
    }
    return 0;
}
// 方法二：找规律
#include <iostream>
using namespace std;

int main()
{
    int n;
    while (cin >> n) // 多组输⼊
    {
        int ret = 1;
        while (ret - 1 <= n) ret *= 2;
        cout << ret / 2 - 1 << endl;
    }
    return 0;
}

// 2.求和
#include <iostream>
using namespace std;

int n, m;
bool vis[11];
int path;

void DFS(int pos)
{
    if (path == m)
    {
        for (int i = 1; i <= n; ++i)
            if (vis[i])
                cout << i << ' ';
        cout << endl;
        return;
    }
    if (path > m || pos > n) return;

    // 选pos
    path += pos;
    vis[pos] = true;
    DFS(pos + 1);
    path -= pos;
    vis[pos] = false;

    // 不选pos
    DFS(pos + 1);
}

int main()
{
    cin >> n >> m;
    DFS(1);

    return 0;
}

// 3.计算字符串的编辑距离
#include <iostream>
#include <string>
using namespace std;

const int N = 1010;

int dp[N][N];
char a[N];
char b[N];
int main() {
    string s1;
    string s2;
    cin >> s1 >> s2;
    int n = s1.size();
    int m = s2.size();

    // 填入char数组中，为了让下标从 1 开始
    for (int i = 1; i <= n; ++i)
        a[i] = s1[i - 1];
    for (int i = 1; i <= m; ++i)
        b[i] = s2[i - 1];

    // 初始化
    for (int i = 1; i <= n; ++i)
        dp[i][0] = i;
    for (int j = 1; j <= m; ++j)
        dp[0][j] = j;

    // 填表
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (a[i] == b[j])
                dp[i][j] = dp[i - 1][j - 1];
            else
                dp[i][j] = min(dp[i - 1][j], min(dp[i][j - 1], dp[i - 1][j - 1])) + 1;
        }
    }

    // 返回
    cout << dp[n][m] << endl;
    return 0;
}